#include <bits/stdc++.h>
// 2025/04/04
// tag:
// Author: Forever
using namespace std;
using int64 = int64_t;

int n, s[301], dp[301][301];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> s[i];
    for (int i = 1; i <= n; i++)
        s[i] += s[i - 1];
    for (int len = 2; len <= n; len++)
        for (int l = 1; l + len - 1 <= n; l++) {
            int r = l + len - 1;
            for (int k = l; k < r; k++)
                dp[l][r] = min(dp[l][r] == 0 ? INT_MAX : dp[l][r], dp[l][k] + dp[k + 1][r] + s[r] - s[l - 1]);
        }
    cout << dp[1][n] << endl;
    return 0;
}